
var alarmCollect = eval("("+$("#alarm").val()+")"); //先将对象转成json
$(function () {
    //初始化信息
    initData();
    //点击关闭按钮
    $('#close').click(function(){
        close();
    });
    //点击忽略/取消忽略
    $("#ignore").click(function(){
        ignore();
    });
    //点击解决按钮
    $("#process").click(function () {
        solveAlarm();
    })
})

function initData(){
    var lev = "";
    if (alarmCollect.alarmLevel == 1) {
        lev = "critical";
    }else if(alarmCollect.alarmLevel == 2){
        lev = "error";
    }else if(alarmCollect.alarmLevel == 3){
        lev = "warning";
    }
    var alarmType = "";
    switch (alarmCollect.alarmType) {
        case 0:
            alarmType = "配置";
            break;
        case 1:
            alarmType = "性能";
            break;
        case 2:
            alarmType = "容量";
            break;
        case 3:
            alarmType = "状态";
            break;
        case 4:
            alarmType = "服务";
            break;
        case 5:
            alarmType = "进程";
            break;
        case 6:
            alarmType = "温度";
            break;
        case 7:
            alarmType = "PING";
            break;
        case 8:
            alarmType = "数据库";
            break;
    }
    var alarmState = "";
    switch (alarmCollect.alarmState) {
        case 1:
            alarmState = "已处理";
            $("#process span").text("已解决");
            $("#ignore").attr("disabled","disabled").removeClass("press_btn3").addClass("press_btn1");
            $("#ignore").attr("title","此告警已解决");
            break;
        case 0:
            alarmState = "未处理";
            break;
        case 2:
            alarmState = "忽略";
            $("#ignore span").text("取消忽略");
            break;
    }
    $("#alarmType").html(alarmType);
    $("#alarmHost").html(alarmCollect.insName+"("+alarmCollect.insIp+")");
    $("#alarmTime").html(formatDateTime(new Date(alarmCollect.lastAlarmTime)));
    $("#alarmLevel").html(lev);
    $("#indicatorName").html(alarmCollect.indicatorName);
    $("#partName").html(alarmCollect.partName);
    $("#piName").html(alarmCollect.piName);
    $("#alarmNumber").html(alarmCollect.alarmNumber+"次");
    $("#ignoreNumber").html(alarmCollect.ignoreNumber+"次");
    $("#alarmState").html(alarmState);
    $("#alarmMessage").html(alarmCollect.alarmMessage);
    $("#processDescription").html(alarmCollect.processDescription == "null"?"":alarmCollect.processDescription);
}

function close() {
    var index = parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);
}

function ignore(){
    var ignoreState;
    if ($("#ignore span").text() == "忽略") {
        ignoreState = 2;
    }else{
        ignoreState = 0;
    }
    $.ajax({
        url:basePath+"/radar/alarmControl/alarmIgnore.do",
        type:"POST",
        dataType:"json",
        data:{
            "alarmIds":alarmCollect.alarmCollectId,
            "state":ignoreState
        },
        success:function(result){
            if(result.code == "200"){
                if (ignoreState == 2) {
                    parent.layer.msg("忽略成功!",{time:1000});
                    $("#ignore span").text("取消忽略");
                    $("#alarmNumber").html("0次");
                    $("#ignoreNumber").html(alarmCollect.ignoreNumber+alarmCollect.alarmNumber+"次");
                    parent.window.reload();
                }else{
                    parent.layer.msg("取消忽略成功!",{time:1000});
                    $("#ignore span").text("忽略");
                }
                location.reload();
            }else{
                layer.msg("操作失败", {time: 1000});
            }
        }
    });
}

function solveAlarm() {
    var value = $("#processDescription").val();
    if(value == ""){
        layer.alert("请填写处理信息!");
        return;
    }
    if (value == $("#processDescription").html()){
        layer.msg("无新的处理信息，无法提交", {time: 1000});
        return;
    }
    $.ajax({
        url:basePath+"/radar/alarmControl/solveAlarm.do",
        type:"POST",
        dataType:"json",
        data:{
            "alarmId":alarmCollect.alarmCollectId,
            "processDescription":value
        },
        success:function(result){
            if(result.code == "200"){
                parent.layer.msg("告警已解决", {time: 1000});
                parent.window.reload();
            }else{
                parent.layer.msg("操作失败", {time: 1000});
                parent.window.reload();
            };
        }
    })
}











